package com.rjh.concurrent.create;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Slf4j(topic = "c.FutureTaskModel")
public class FutureTaskModel {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable callable = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask(callable);
        Thread t1 = new Thread(futureTask);
        t1.setName("t1");
        t1.start();
        Integer integer = futureTask.get();
        log.debug("ret {}",integer);
        log.debug("running");
    }
}

@Slf4j(topic = "c.MyCallable")
class MyCallable implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        Thread.sleep(1000);
        log.debug("running");
        return 100;
    }
}
